// FrameBuffer.h
//
#ifndef FRAMEBUFFER_ONCE
#define FRAMEBUFFER_ONCE

#include "Framework_Exports.h"


#include "OpenGL.h"
#include "Texture.h"

namespace OpenGL {

class FWK_API FrameBuffer
{
private:
	struct Attachment
	{
		GLenum attachmentPoint;	    // GL_COLOR_ATTACHMENT0, ...
		GLenum attachmentType;      // GL_TEXTURE_1D,GL_TEXTURE_2D, ...
		GLuint attachmentID;		// texture ID
	};


	int        _width;
	int        _height;
	bool       _bound;
	GLuint     _fbo;

	GLenum     _depthFormat;
	GLuint     _depthBuffer;

	std::vector<Attachment> _attachments;

	void init();
	void destroy();

public:
	FrameBuffer();
	~FrameBuffer();

	bool create();
	void bind( int width, int height );

	void unbind();
	void clear(float r = 0.f, float g = 0.f, float b = 0.f, float a = 1.f);
	bool attachTextureTarget( const TexturePtr &texture, GLenum attachPoint );
	bool detachTextureTarget( GLenum attachPoint );
	bool attachDepthRenderTarget( GLenum depthFormat, int width, int height );
	//bool attachStencilRenderTarget(); //@TODO

	bool   isBound()     const;
	bool   isValid()     const;

	std::string info() const;
	bool        checkStatus() const;
};

}
#endif